/**
 * Created by radish608 on 17-4-19.
 */
public class tempuse {
    public static void main(String[] args) {
        //定义一个数组，比如
        int arr[] = {1,2,3,4,5,6,7,8};

        //打印原始数组的值
        for(int i:arr){
            System.out.print(i + " ");
        }
        System.out.println();

        // 添加代码删除上面数组中的5
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i]==5) {
                for (int j = i; j < arr.length-1; j++) {
                    arr[j] = arr[j+ 1];
                    arr[j + 1] = 0;
                }
            }
        }

        //打印出 1 2 3 4 6 7 8 0
        for(int i:arr){
            System.out.print(i + " ");
        }
        System.out.println();

        // 添加代码再在4后面5
        int j;
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i]==4) {
                for (j = arr.length-1; j > i+1 ; j--) {
                    arr[j] = arr[j-1];
                    arr[j - 1] = 5;
                }
            }
        }

        //打印出 1 2 3 4 5 6 7 8
        for(int i:arr){
            System.out.print(i + " ");
        }
        System.out.println();
    }
}
